﻿<phone:PhoneApplicationPage x:Class="WinSource.Views.SavedArticlesPage"
                            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                            xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
                            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                            xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                            xmlns:AppBarUtils="clr-namespace:AppBarUtils;assembly=AppBarUtils"
                            xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
                            xmlns:Controls="clr-namespace:WinSource.Controls"
                            xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WP71"
                            DataContext="{Binding SavedArticlesViewModel, Source={StaticResource Locator}}"
                            mc:Ignorable="d"
                            d:DesignHeight="728"
                            d:DesignWidth="480">

  <phone:PhoneApplicationPage.Resources>

    <Style x:Key="GridStyle"
           TargetType="Grid">
      <Setter Property="Background"
              Value="{StaticResource BackgroundColor}" />
    </Style>

    <Style x:Key="TitleControlStyle"
           TargetType="Controls:TitleControl">
      <Setter Property="Background"
              Value="Black" />
      <Setter Property="TitleName"
              Value="{StaticResource ApplicationName}" />
    </Style>


  </phone:PhoneApplicationPage.Resources>

  <Grid Style="{StaticResource GridStyle}">

    <Grid.RowDefinitions>
      <RowDefinition Height="Auto" />
      <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <Controls:TitleControl Style="{StaticResource TitleControlStyle}"
                           PageName="saved articles" />

    <Controls:LongListSelector Grid.Row="1"
                               Margin="24,0"
                               IsFlatList="True"
                               ItemsSource="{Binding Articles}"
                               SelectedItem="{Binding CurrentArticle, Mode=TwoWay}"
                               VerticalAlignment="Top">

      <i:Interaction.Triggers>
        <i:EventTrigger EventName="Tap">
          <cmd:EventToCommand Command="{Binding ReadCurrentArticleCommand}"
                              PassEventArgsToCommand="False" />
        </i:EventTrigger>
      </i:Interaction.Triggers>

      <Controls:LongListSelector.ItemTemplate>
        <DataTemplate>

          <Grid Margin="0,0,0,12">

            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="Auto" />
              <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <Image Source="{Binding Thumbnail}"
                   Height="125"
                   HorizontalAlignment="Center"
                   Width="125"
                   Stretch="UniformToFill"
                   VerticalAlignment="Center" />

            <StackPanel Grid.Column="1"
                        Margin="10,0,0,0">

              <TextBlock Foreground="{StaticResource TextBrush}"
                         Text="{Binding Title}"
                         TextWrapping="Wrap" />

              <TextBlock Foreground="{StaticResource RedBrush}"
                         Text="{Binding Author}" />

            </StackPanel>

          </Grid>

        </DataTemplate>
      </Controls:LongListSelector.ItemTemplate>

    </Controls:LongListSelector>

  </Grid>


  <phone:PhoneApplicationPage.ApplicationBar>

    <shell:ApplicationBar BackgroundColor="{StaticResource RedColor}"
                          ForegroundColor="White"
                          
                          IsVisible="True" Mode="Minimized">

      <shell:ApplicationBar.MenuItems>

        <shell:ApplicationBarMenuItem Text="delete all" />

      </shell:ApplicationBar.MenuItems>

    </shell:ApplicationBar>

  </phone:PhoneApplicationPage.ApplicationBar>

  <i:Interaction.Behaviors>

    <AppBarUtils:AppBarItemCommand Type="MenuItem"
                                   Id="delete all"
                                   Command="{Binding DeleteAllArticlesCommand}" />

  </i:Interaction.Behaviors>

</phone:PhoneApplicationPage>